{% extends 'encyclopedia/base.html' %}

{% block title %}{% if form.instance.pk %}编辑配件 - {{ form.instance.title }}{% else %}添加新配件{% endif %} - 相机百科{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h2 class="card-title mb-0">
                        {% if form.instance.pk %}
                        编辑配件：{{ form.instance.title }}
                        {% else %}
                        添加新配件
                        {% endif %}
                    </h2>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        
                        {% if form.errors %}
                        <div class="alert alert-danger mb-4">
                            <strong>表单有错误，请修正：</strong>
                            <ul>
                                {% for field in form %}
                                    {% for error in field.errors %}
                                        <li>{{ field.label }}: {{ error }}</li>
                                    {% endfor %}
                                {% endfor %}
                                {% for error in form.non_field_errors %}
                                    <li>{{ error }}</li>
                                {% endfor %}
                            </ul>
                        </div>
                        {% endif %}
                        
                        <div class="form-group">
                            <label for="{{ form.title.id_for_label }}">配件名称 *</label>
                            {{ form.title }}
                        </div>
                        
                        <div class="form-group">
                            <label for="{{ form.brand.id_for_label }}">品牌</label>
                            {{ form.brand }}
                        </div>
                        
                        <div class="form-group">
                            <label for="{{ form.category.id_for_label }}">分类 *</label>
                            {{ form.category }}
                        </div>
                        
                        <div class="form-group">
                            <label for="{{ form.price_range.id_for_label }}">价格区间</label>
                            {{ form.price_range }}
                        </div>
                        
                        <div class="form-group">
                            <label for="{{ form.compatible_cameras.id_for_label }}">兼容相机（按住Ctrl/Cmd可多选）</label>
                            {{ form.compatible_cameras }}
                        </div>
                        
                        <div class="form-group">
                            <label for="{{ form.content.id_for_label }}">详细介绍 *</label>
                            {{ form.content }}
                        </div>
                        
                        <div class="mt-4 text-right">
                            <button type="submit" class="btn btn-primary">保存</button>
                            <a href="{% url 'encyclopedia:accessory_list' %}" class="btn btn-secondary ml-2">取消</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}